package org.mifos.boss.business;

import java.util.List;

import org.apache.log4j.Logger;
import org.mifos.boss.domainmodel.User;
import org.mifos.boss.persistence.UserPersistenceInterface;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

@Transactional
@Repository(value = "userBusiness")
public class UserBusinessImpl extends BaseBossBusiness implements
		UserBusinessInterface {

	protected static Logger logger = Logger.getLogger(UserBusinessImpl.class);

	@Autowired
	@Qualifier("userPersistence")
	UserPersistenceInterface userPersistence;

	@Transactional
	public boolean validateUser(User user) {
		return userPersistence.validateUser(user);
	}

	@Transactional
	public boolean addUser(User user) {
		try {
			userPersistence.addUser(user);
		} catch (Exception ex) {
			return false;
		}
		return true;
	}

	@Transactional
	public List<User> listUser() {
		List<User> listUser = null;
		try {
			listUser = userPersistence.listUser();
		} catch (Exception ex) {
			logger.info(ex);
		}
		return listUser;
	}

	@Transactional
	public boolean removeUser(String userID) {
		try {
			userPersistence.removeUser(userID);
		} catch (Exception ex) {
			return false;
		}
		return true;
	}

}
